package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.ann.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Random;

@Mapper
public interface dishMapper {
    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> select(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish selectId(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 删除
     * @param id
     */
    @Delete("delete from dish where id=#{id}")
    void DeleteId(Long id);

    /**
     * //批量删除菜品表中的数据
     * @param ids
     */
    void DeleteIds(List<Long> ids);

    /**
     * 根据分类id查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 判断套餐里是否有菜品
     * @param setmealId
     * @return
     */
    @Select("select dish.* from dish left join setmeal_dish on dish.id=setmeal_dish.dish_id where setmeal_dish.setmeal_id=#{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    /**
     * C端根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select dish.*,dish_flavor.* from dish left join dish_flavor on dish.id = dish_flavor.dish_id where category_id=#{categoryId}")
    List<DishVO> selectByCategoryId(Long categoryId);

    /**
     * 根据id查询
     * @param dishId
     */
    @Select("select * from dish where id=#{dishId}")
    Dish getDishId(Long dishId);

    /**
     * 已停售菜品数量
     * @param
     */
    @Select("select count(id) from dish where status = #{status}")
    Integer getStatus(int status);
}
